export const handleCreateDatePicker = (val) => {
  let that = val;
  const years = [];
  const months = [
    {
      label: that.$t("一月"),
      value: "01",
    },
    {
      label: that.$t("二月"),
      value: "02",
    },
    {
      label: that.$t("三月"),
      value: "03",
    },
    {
      label: that.$t("四月"),
      value: "04",
    },
    {
      label: that.$t("五月"),
      value: "05",
    },
    {
      label: that.$t("六月"),
      value: "06",
    },
    {
      label: that.$t("七月"),
      value: "07",
    },
    {
      label: that.$t("八月"),
      value: "08",
    },
    {
      label: that.$t("九月"),
      value: "09",
    },
    {
      label: that.$t("十月"),
      value: "10",
    },
    {
      label: that.$t("十一月"),
      value: "11",
    },
    {
      label: that.$t("十二月"),
      value: "12",
    },
  ];
  for (let i = 1970; i <= 2099; i++) {
    years.push({
      label: `${i}` + that.$t("年"),
      value: i,
    });
  }
  // for (let i = 1; i <= 12; i++) {
  //   months.push({
  //     label: `${i}月`,
  //     value: i
  //   })
  // }
  return {
    years,
    months,
  };
};
export function parseTime(time, cFormat) {
  if (arguments.length === 0) {
    return null;
  }
  const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
  let date;
  if (typeof time === "object") {
    date = time;
  } else {
    if (typeof time === "string" && /^[0-9]+$/.test(time)) {
      time = parseInt(time);
    }
    if (typeof time === "number" && time.toString().length === 10) {
      time = time * 1000;
    }
    date = new Date(time);
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay(),
  };
  const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
    const value = formatObj[key];
    // Note: getDay() returns 0 on Sunday
    if (key === "a") {
      return ["日", "一", "二", "三", "四", "五", "六"][value];
    }
    return value.toString().padStart(2, "0");
  });
  return time_str;
}
